package com.study.lintcode.my.code_10;

/**********************************************************************
 * &lt;p&gt;文件名：Example_1.java &lt;/p&gt;
 * &lt;p&gt;文件描述：(https://www.lintcode.com/problem/a-b-problem/)
 * @project_name：LintCode
 * @author zengshunyao
 * @create 2019/1/5 21:56
 * @history
 * @department：政务事业部
 * Copyright ChengDu Funi Cloud Code Technology Development CO.,LTD 2014
 *                    All Rights Reserved.
 */
public class Example_2 {
    /*
     * @param n: An integer
     * @return: An integer, denote the number of trailing zeros in n!
     */
    public long trailingZeros(long n) {
        // write your code here, try to do it without arithmetic operators.
        //1,2,3,4,5,6,7,8,9,10.....100,.....,1000,.....
        //只要乘以5的倍数就会产生0
        //5,10,15,20,25,30...,100...,1000.=>5*(1,2,3,4,5,6,7,..,25..,625..)=>5*5*(1,2,3,4,5,)
        //n/5+n/25+n/625
        long count = 0;
//        long pwr = 25;
//        for (long temp = 5; temp <= n; temp+=5) {
//            // for循环内部的temp都是5的倍数，因此首先进行+1操作
//            count++;
//            pwr = 25;
//            // 判断是不是25、125、625...的倍数，并根据每次pwr的变化进行+1操作
//            while (temp % pwr == 0) {
//                count++;
//                pwr *= 5;
//            }
//        }


        while (n / 5 > 0) {
            count += n / 5;
            n = n / 5;
        }

        return count;
    }


    public static void main(String[] args) {
        //0,0=>1
        //0,9=>1
        //1,12=>5
        //2,12=2
        System.out.println(new Example_2().trailingZeros(104));
    }
}
